package org.xdq.join练习;

public class Test {
    public static void main(String[] args) {

        Thread t2 = new Thread(()->{
            for(int i=1;i<=1000;i++){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        },"T2");

        t2.start();

        new Thread(()->{
            for(int i=1;i<=1000;i++){
                System.out.println(Thread.currentThread().getName()+":"+i);
                //本线程打印到300后，无条件等待T2线程执行完毕后再接着打印
                if(i==300){
                    try {
                        System.out.println(Thread.currentThread().getName()+":等待中.......");
                        t2.join();//当前线程进入阻塞状态，等待T2线程执行完毕，解除阻塞状态，进入就绪状态
                        System.out.println(Thread.currentThread().getName()+":等待结束！！！！！！");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"T1").start();





    }
}
